package com.test3;

import java.util.ArrayList;
import java.util.Iterator;

public class GenericList {
    public static void main(String[] args) {
        //这里泛型定义了用String类型，就只能添加String类型的数据
        ArrayList<String> arrayList = new ArrayList<>();
        arrayList.add("李白");
        arrayList.add("吕布");
//        arrayList.add(21312);//会报错
        arrayList.forEach(e -> System.out.println(e));

        ArrayList<Students> arrayList1 = new ArrayList<>();
        Students s1 = new Students("刘德华",20);
        Students s2 = new Students("黎明",22);
        Students s3 = new Students("张学友",18);
        arrayList1.add(s1);
        arrayList1.add(s2);
        arrayList1.add(s3);
        Iterator<Students> it = arrayList1.iterator();
        while (it.hasNext()){
            Students s = it.next();
            System.out.println(s.toString());
        }
    }
}
